package com.nt.oam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.nt.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nt.common.annotation.Log;
import com.nt.common.core.controller.BaseController;
import com.nt.common.core.domain.AjaxResult;
import com.nt.common.enums.BusinessType;
import com.nt.oam.domain.AntAssetCorrelation;
import com.nt.oam.service.IAntAssetCorrelationService;
import com.nt.common.utils.poi.ExcelUtil;
import com.nt.common.core.page.TableDataInfo;

/**
 * 资产关联Controller
 *
 * @author JZFeng
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/oam/correlation")
public class AntAssetCorrelationController extends BaseController {
    @Autowired
    private IAntAssetCorrelationService antAssetCorrelationService;

    /**
     * 查询资产关联列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:correlation:list')")
    @GetMapping("/list")
    public TableDataInfo list(AntAssetCorrelation antAssetCorrelation) {
        startPage();
        List<AntAssetCorrelation> list = antAssetCorrelationService.selectAntAssetCorrelationList(antAssetCorrelation);
        return getDataTable(list);
    }

    /**
     * 导出资产关联列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:correlation:export')")
    @Log(title = "资产关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AntAssetCorrelation antAssetCorrelation) {
        List<AntAssetCorrelation> list = antAssetCorrelationService.selectAntAssetCorrelationList(antAssetCorrelation);
        ExcelUtil<AntAssetCorrelation> util = new ExcelUtil<AntAssetCorrelation>(AntAssetCorrelation.class);
        util.exportExcel(response, list, "资产关联数据");
    }

    /**
     * 获取资产关联详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:correlation:query')")
    @GetMapping(value = "/{assetId}")
    public AjaxResult getInfo(@PathVariable("assetId") Long assetId) {
        return success(antAssetCorrelationService.selectAntAssetCorrelationByAssetId(assetId));
    }

    /**
     * 新增资产关联
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:correlation:add')")
    @Log(title = "资产关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AntAssetCorrelation antAssetCorrelation) {
        return toAjax(antAssetCorrelationService.insertAntAssetCorrelation(antAssetCorrelation));
    }

    /**
     * 修改资产关联
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:correlation:edit')")
    @Log(title = "资产关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AntAssetCorrelation antAssetCorrelation) {
        return toAjax(antAssetCorrelationService.updateAntAssetCorrelation(antAssetCorrelation));
    }

    /**
     * 删除资产关联
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:correlation:remove')")
    @Log(title = "资产关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{assetIds}")
    public AjaxResult remove(@PathVariable Long[] assetIds) {
        return toAjax(antAssetCorrelationService.deleteAntAssetCorrelationByAssetIds(assetIds));
    }


    /**
     * 资产名称列表
     */
    @Anonymous
    @Log(title = "资产名称列表", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('oam:correlation:query')")
    @GetMapping("/assets/name")
    public AjaxResult assetsNameList(@RequestParam(required = false) String assetsName) {
        return success(antAssetCorrelationService.getAssetsNameList(assetsName));
    }
}
